import numpy as np

# 示例矩阵（3x2）
A = np.array([[1, 2], [3, 4], [5, 6]])

# 计算 SVD
U, Sigma, VT = np.linalg.svd(A)

print("U (左奇异向量矩阵):\n", U)
print("Sigma (奇异值):\n", Sigma)  # 一维数组，按从大到小排列
print("V^T (右奇异向量矩阵的转置):\n", VT)

# 重构矩阵 A（近似）
Sigma_matrix = np.zeros((A.shape[0], A.shape[1]))  # 构造 Σ 矩阵
Sigma_matrix[:len(Sigma), :len(Sigma)] = np.diag(Sigma)  # 填充奇异值
A_reconstructed = U @ Sigma_matrix @ VT  # A = U Σ V^T

print("\n重构的 A:\n", A_reconstructed)